using UnityEngine;

public class RCCCamManager : MonoBehaviour
{
	private RCCCarCamera carCamera;

	private RCCCameraOrbit orbitScript;

	private RCCCockpitCamera cockpitCamera;

	private RCCWheelCamera wheelCamera;

	public bool useOrbitCamera;

	public bool useFixedCamera;

	internal float dist = 10f;

	internal float height = 5f;

	internal int cameraChangeCount;

	internal Transform target;

	private void Start()
	{
		cameraChangeCount = 0;
		carCamera = GetComponent<RCCCarCamera>();
		target = carCamera.playerCar;
		if ((bool)GetComponent<RCCCameraOrbit>())
		{
			orbitScript = GetComponent<RCCCameraOrbit>();
		}
		else
		{
			orbitScript = base.gameObject.AddComponent<RCCCameraOrbit>();
		}
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.C))
		{
			ChangeCamera();
		}
	}

	public void ChangeCamera()
	{
		target = carCamera.playerCar;
		if (!target)
		{
			return;
		}
		cameraChangeCount++;
		if (cameraChangeCount >= 5)
		{
			cameraChangeCount = 0;
		}
		if ((bool)target.GetComponent<RCCCarCameraConfig>())
		{
			dist = target.GetComponent<RCCCarCameraConfig>().distance;
			height = target.GetComponent<RCCCarCameraConfig>().height;
			carCamera.distance = dist;
			carCamera.height = height;
		}
		if (useOrbitCamera)
		{
			orbitScript.target = target.transform;
			orbitScript.distance = dist;
		}
		if ((bool)target.GetComponentInChildren<RCCCockpitCamera>())
		{
			cockpitCamera = target.GetComponentInChildren<RCCCockpitCamera>();
		}
		if ((bool)target.GetComponentInChildren<RCCWheelCamera>())
		{
			wheelCamera = target.GetComponentInChildren<RCCWheelCamera>();
		}
		switch (cameraChangeCount)
		{
		case 0:
			if (useFixedCamera && (bool)UnityEngine.Object.FindObjectOfType<RCCMainFixedCam>())
			{
				Object.FindObjectOfType<RCCMainFixedCam>().canTrackNow = false;
			}
			carCamera.enabled = true;
			orbitScript.enabled = false;
			carCamera.transform.SetParent(null);
			break;
		case 1:
			if (!useOrbitCamera)
			{
				ChangeCamera();
				break;
			}
			orbitScript.enabled = true;
			carCamera.enabled = false;
			carCamera.transform.SetParent(null);
			break;
		case 2:
			if (!cockpitCamera)
			{
				ChangeCamera();
				break;
			}
			orbitScript.enabled = false;
			carCamera.enabled = false;
			carCamera.transform.SetParent(cockpitCamera.transform);
			carCamera.transform.localPosition = Vector3.zero;
			carCamera.transform.localRotation = Quaternion.identity;
			carCamera.GetComponent<Camera>().fieldOfView = 60f;
			break;
		case 3:
			if (!wheelCamera)
			{
				ChangeCamera();
				break;
			}
			orbitScript.enabled = false;
			carCamera.enabled = false;
			carCamera.transform.SetParent(wheelCamera.transform);
			carCamera.transform.localPosition = Vector3.zero;
			carCamera.transform.localRotation = Quaternion.identity;
			carCamera.GetComponent<Camera>().fieldOfView = 60f;
			break;
		case 4:
			if (!useFixedCamera)
			{
				ChangeCamera();
				break;
			}
			orbitScript.enabled = false;
			carCamera.enabled = false;
			carCamera.transform.SetParent(null);
			Object.FindObjectOfType<RCCMainFixedCam>().mainCamera = GetComponent<Camera>();
			Object.FindObjectOfType<RCCMainFixedCam>().player = target;
			Object.FindObjectOfType<RCCMainFixedCam>().canTrackNow = true;
			break;
		}
	}
}
